<template>
  <div style="margin: 15px; margin-right: 30px;">
    <el-form ref="form" :rules="rules" :model="form" label-width="100px">
      <el-row>
        <el-col :span="24">
          <el-form-item label="司机姓名" prop="name">
            <el-input v-model="form.name" placeholder="请输入联系人姓名" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="司机电话" prop="phone">
            <el-input v-model="form.phone" placeholder="请输入联系人电话" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="绑定车辆" prop="vehicleCode">
            <el-select v-model="form.vehicleCode" filterable placeholder="请选择绑定车辆" clearable>
              <el-option
                v-for="item in filterVehicleBindList"
                :key="item.code"
                :label="item.licenseNumber"
                :value="item.code"
                :filterable="true"
                :remote="true"
                :remote-method="remoteMethod"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="funcCancel">取 消</el-button>
      <el-button type="primary" @click="funcSubmit">确 定</el-button>
    </div>
  </div>
</template>
<script>
import { bindVehicle } from '@/api/driver'
export default {
  name: 'TeamDriverBind',
  props: {
    parentData: {
      type: Object,
      default() {
        return {
          areaOptions: [],
          vehicleBindList: [],
          vehicleTypeAllowList: [],
          vehicleClassificationList: [],
          vehicleLengthList: [],
          vehicleWidthList: [],
          vehicleHighList: [],
          vehicleTonnageList: [],
          locationSourceList: []
        }
      }
    }
  },
  data() {
    return {
      uploadUrl: this.BASE_API_URL + 'ntocc-tps-api/fileUpload',
      filterVehicleBindList: [],
      form: {
        name: '',
        phone: '',
        vehicleCode: '',
        partyCode: ''
      },
      rules: {
        vehicleCode: [
          { required: true, message: '请选择绑定车辆', trigger: 'change' }
        ]
      }
    }
  },
  created() {
    this.filterVehicleBindList = this.parentData.vehicleBindList
  },
  methods: {
    getInfo(row) {
      this.form.name = row.name
      this.form.phone = row.phone
      this.form.vehicleCode = ''
      this.form.partyCode = row.partyCode
    },
    remoteMethod(query) {
      var list = this.parentData.vehicleBindList.filter(item => item.licenseNumber.indexOf(query) > -1)
      this.filterVehicleBindList = list
    },
    funcSubmit() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          var data = Object.assign({}, this.form, { teamCode: this.teamCode })
          bindVehicle(data).then(response => {
            this.$message({ message: response.msg, type: 'success' })
            this.$emit('fatherBindMethod')
          })
        } else {
          this.$message.error('必选项不能为空!')
        }
      })
    },
    funcCancel() {
      this.$emit('fatherCancelMethod', 'bind')
    }
  }
}
</script>
<style scoped>
.dialog-footer {
  margin: 15px 0 15px 0;
  width: 175px;
  float: right;
}
.el-select {
  width: 100%;
}
</style>
